package com.paradise.phone.utils;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by Sisyphus on 2017/11/24.
 */

public class MySwipeRefreshLayout extends SwipeRefreshLayout {

    private float mLastMoveX = 0;
    private float mLaxtMoveY = 0;

    public MySwipeRefreshLayout(Context context) {
        super(context);
    }

    public MySwipeRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        boolean isIntercept = false;
        float x = ev.getX();
        float y = ev.getY();

        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                isIntercept = false;
                break;
            case MotionEvent.ACTION_MOVE:
                float distanceX = mLastMoveX - x;
                float distanceY = mLaxtMoveY - y;
                if (Math.abs(distanceY) >= Math.abs(distanceX)){
                    isIntercept = true;
                }else {
                    isIntercept = false;
                }
                break;
            case MotionEvent.ACTION_UP:
                isIntercept = false;
                break;
            default:
                break;

        }
        mLastMoveX = x;
        mLaxtMoveY = y;

        return isIntercept;
    }
}
